﻿using System;
using System.Linq;
using Coder.Workflow.Mapping;
using Coder.Workflow;
using Identity;
using Microsoft.EntityFrameworkCore;

namespace Coder.Workflow
{
    public class WorkflowDbContext : MemberDbContextBase

    {
        private readonly Type _generatorNumberType;

        public WorkflowDbContext(DbContextOptions options, Type generatorNumberType) : base(options)
        {
            _generatorNumberType = generatorNumberType;
        }

        // public IQueryable<WorkTask> WorkflowItems => Set<WorkTask>();


        public IQueryable<WorkActivity> WorkActivities => Set<WorkActivity>();

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            ///workProcess

            builder.ApplyConfiguration(new WorkProcessMapping());
            builder.ApplyConfiguration(new WorkTaskMapping());
            builder.ApplyConfiguration(new WorkActivityMapping());
            builder.ApplyConfiguration(new ProcessInstanceMapping(_generatorNumberType));

            builder.Entity<WorkProcess>().ToTable("wf_WorkProcess");
            builder.Entity<WorkActivity>().ToTable("wf_WorkActivity");
            builder.Entity<WorkTask>().ToTable("wf_WorkTask");
            builder.Entity<ProcessInstance>().ToTable("wf_proIns");
        }
    }
}